<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.bill.common.user.dto.RegisterUserQueryDTO"%>
<%@page import="com.bill.common.user.service.IRegisterUserService"%>
<%@page import="com.bill.common.user.dto.AccountDTO"%>
<%@page import="com.bill.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/declarationCenter.jsp");
	return;
}
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
IRegisterUserService registerUserService = (IRegisterUserService)ac.getBean("registerUserService");
RegisterUserQueryDTO qdto = new RegisterUserQueryDTO();
//registerUser!findDirectPushUserPager.action?registerUserQueryDTO.loginName=${session.loginName}&sord=desc&sidx=status
qdto.setDeclarationCenters((String)session.getAttribute("loginName"));
int pages = 1;
String sidx = "status";
String sord="desc";
if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;
qdto.setStart( start );
qdto.setLimit( rows );
PageDTO pageDTO = registerUserService.findRegisterUserPager(qdto, sord, sidx);
if(pageDTO!=null){
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
}
request.setAttribute("pageDTO",pageDTO);

//我推荐已激活
Integer dcActiveQuy = registerUserService.userCount((String)session.getAttribute("loginName"),"DeclarationCenterActivation",null);
request.setAttribute("dcActiveQuy",dcActiveQuy);

request.setAttribute("pageUrl","declarationCenter.jsp?loginName="+ qdto.getDeclarationCenters());
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.operateCenter"/>-<fmt:message key="i18n.title"/> </title>
<link rel="shortcut icon" href="../index/favicon.png" />
<link rel="stylesheet" type="text/css" href="css/style1.css">
<script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="../scripts/script.js"></script>
</head>
<body>
<div class="account">
	<div class="top2" style="background:#ffffed;">
	<a class="top2L" ><fmt:message key="i18n.yewuManage"/> &gt; <fmt:message key="i18n.operateCenter"/>
		(<fmt:message key="i18n.zong"/>：${pageDTO.totalSize }，<fmt:message key="i18n.weijihua"/>：${pageDTO.totalSize-dcActiveQuy}，<fmt:message key="i18n.yijihua"/>：${dcActiveQuy })
	</a>
	<div class="top2R">&nbsp;</div>
	</div>
	<div class="cont" style="padding: 0;">
    	<div>
			<table style="margin-top: 0px;" class="txList" width="100%" cellspacing="0" cellpadding="0">
				<tr>
       				<th><fmt:message key="i18n.xuhao"/></th>
       				<th><fmt:message key="i18n.userbianhao"/></th>
       				<th><fmt:message key="i18n.piUserName"/></th>
       				<th><fmt:message key="i18n.userlevel"/></th>
       				<th><fmt:message key="title.touZhiMoney" /></th>
       				<th><fmt:message key="i18n.regTime"/></th>
       				<th><fmt:message key="i18n.recommendUserId"/></th>
       				<th><fmt:message key="i18n.operation"/></th>
       				<th>删除</th>
				</tr>
	   			<c:forEach items="${pageDTO.data}" var="data">
					<tr class="color1">
						
        					<td>${data.registerUserId }</td>
        					<td>${data.loginName}</td>
        					<td>${data.userName}</td>
        					<td><fmt:message key="${data.registerLevel}" /></td>
        					<td>${data.registerMoney}</td>
        					<td><fmt:formatDate value="${data.registerTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
        					<td>${data.recommendUser}</td>
        					<td>
        						<c:if test="${data.status eq 'Activation'}"><fmt:message key="i18n.yijihua"/></c:if>
        						<c:if test="${data.status ne 'Activation'}">
        						<a id="acuser_${data.registerUserId}" href="javascript:accountActivate('${data.loginName}','${data.registerUserId}');">[<fmt:message key="i18n.clickJihuo"/>]</a>
        						</c:if>
        					</td>
        					<td>
        						<c:if test="${data.status ne 'Activation'}">
        						<a style="color: red;" href="javascript:delateRegister('${data.loginName}');">[<fmt:message key="i18n.delete"/>]</a>
        						</c:if>
        						</td>
        				
					</tr>
	   			</c:forEach>
				<c:if test="${empty pageDTO.data}">
       				<tr>
       					<td colspan="9" align="center"><fmt:message key="i18n.noData"/>!</td>
       				</tr>
       			</c:if>
			</table>
		</div>
		<div class="pageBox" style="margin-top: 40px;">
			<div class="page">
				<a style="color: blue;" href="${pageUrl }&pages=1"><fmt:message key="i18n.firstPage"/></a>
				<c:if test="${pageDTO.page > 1}">
					<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a>
				</c:if>
				<a>${pageDTO.page}/${pageDTO.total}</a>
				<c:if test="${pageDTO.page+1<=pageDTO.total}">
					<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a>
				</c:if>
				<a style="color: blue;" href="${pageUrl }&pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a>
				<a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a>
			</div>
		</div>
       	<form  action="registerUser!userOpt.action" method="post" id="userActivate_form" ></form>
       	<form  action="registerUser!userOpt.action" method="post" id="deleteReguser_form" ></form>
    </div>
</div>
<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../scripts/user/common.js"></script>

<script type="text/javascript">
var isclick=true;
function accountActivate(loginName,userId){ 
	/* 因为如果登录名是邮箱时，$('#acuser_'+loginName).attr()会报错，因此换为用户ID */
	
	$('#userActivate_form').html("<input type='hidden' name='pageUrl' value='declarationCenter.jsp' />"+
			"<input type='hidden' name='optType' value='userActive' />"+
			"<input type='hidden' name='activeType' value='DeclarationCenters' />"+
			"<input type='hidden' name='registerUserDTO.loginName' value='"+loginName+"' />");
	if(confirm('是否确定要激活?')){
		$('#acuser_'+userId).attr("disabled",true);
		if(isclick){
			isclick=false;
			$('#userActivate_form').submit();
		}else{
			alert('操作过于频繁，请稍后再操作!');
		}
		
	}
}
function delateRegister(loginName){
	$('#deleteReguser_form').html("<input type='hidden' name='pageUrl' value='declarationCenter.jsp' />"+
			"<input type='hidden' name='optType' value='UserDel' />"+
			"<input type='hidden' name='loginName' value='"+loginName+"' />");
	if(confirm('!!!!!!!!!!!!!!是否确定要删除?')){
		$('#deleteReguser_form').submit();
	}
}
</script>

</body>
</html>